#!/bin/bash
set -e

if [[ -z "${JIANMU_URL}" ]]
then
  echo "[ERROR] The necessary url configuration is missing"
  exit 1
fi

URL="${JIANMU_URL}"
TIMEOUT=${JIANMU_TIMEOUT}
echo $URL
echo $TIMEOUT
HTTP_CODE=$(curl -o /dev/null -m 10 --connect-timeout $TIMEOUT -s -w %{http_code} $URL) || HTTP_CODE="ERROR"

echo -e "{
     "\"status_code\"" ":" "\"${HTTP_CODE}\""
}" > /usr/resultFile

echo "resultFile:"
cat /usr/resultFile